﻿
Imports remotecall
Imports naming = centrosphere.rc_pac_detector.naming

Public Class rc_pac_emitter
    Inherits rcEmitter(Of rc_pac_client_pool, response)

    Public Sub New(ByVal host As String,
                   ByVal port As Int32,
                   Optional ByVal holdtimeMs As Int64 = tcpTalk4.defaultHoldTimeMs,
                   Optional ByVal livetimeMs As Int64 = tcpTalk4.defaultLiveTimeMs)
        MyBase.New(host, port, holdtimeMs, livetimeMs)
    End Sub

    Protected Overrides Function create_client(ByVal host As String,
                                               ByVal port As Int32,
                                               Optional ByVal holdtimeMs As Int64 = tcpTalk4.defaultHoldTimeMs,
                                               Optional ByVal livetimeMs As Int64 = tcpTalk4.defaultLiveTimeMs) _
                                              As rc_pac_client_pool
        Return New rc_pac_client_pool(host, port)
    End Function

    Protected Overrides Function invoke(ByVal client As rc_pac_client_pool,
                                        ByVal name As String,
                                        ByRef ec As eventComb,
                                        ByVal rtn As pointer(Of response),
                                        ByVal job As ijob) As Boolean
        Dim send As envelope = Nothing
        send = New envelope()
        assert(send.add(naming.ijob, job))
        Return client.invoke(New request(name, send), rtn, ec)
    End Function

    Protected Overrides Function parse_output_ijob(ByVal o As response, ByRef job As ijob) As Boolean
        Return o.argument.get(naming.ijob, job)
    End Function

    Protected Overrides Function parse_output_valid(ByVal o As response) As Boolean
        Return Not o Is Nothing AndAlso Not o.argument Is Nothing
    End Function
End Class
